package auth


import (
	"gitee.com/sdynasty/clever/middleware/jwt"
	"sync"
)

var jwtCreator *jwt.JWT
var once  sync.Once


// 创建Token
func CreateToken(serverNo, userId string) (string, error) {
	once.Do(func() {
		jwtCreator = jwt.NewJWT("clever")
	})
	return jwtCreator.CreateToken(jwt.CustomClaims{
		Pid:            userId,
		ServerNo:       serverNo,
	})
}

// 解析Token
func ParseToken(token string) (*jwt.CustomClaims, error) {
	return jwtCreator.ParseToken(token)
}
